#include "Test.TexturedBatch.h"

#undef  APP_NAME
#define APP_NAME	TestAllFontSymbols
#undef  APP_BASE
#define APP_BASE	TestTexturedBatch


class APP_NAME : public APP_BASE
{
protected:
	BitmapFontPtr	bfont;
	VectorFontPtr	vfont;


public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{}

	~APP_NAME ()
	{
		material.ResetTextures();
		material.SetProgram( null );
	}
	
	void Update (float dt) override
	{
		TestApp::Update( dt );

		ESS()->GetGraphicsEngine()->GetViewport()->Apply();
		ESS()->GetGLStateManager()->ClearColor( color4f( 0.0f, 0.0f, 0.0f, 1.0f ) );
		
		material.SetTexture( 0, bfont->GetTexture() );
		batch.AddBatch( material, Rect2D( rect(-0.99f, 0.0f, 0.99f, 0.99f), rect(0.0f, 0.0f, 1.0f, 1.0f), color4u(255, 0, 0, 255) ) );

		array<TexturePtr>	texs;
		vfont->GetTexturesForLevel( 32, texs );

		if ( not texs.Empty() )
		{
			material.SetTexture( 0, texs.Front() );
			batch.AddBatch( material, Rect2D( rect(-0.99f, -0.99f, 0.99f, 0.0f), rect(0.0f, 0.0f, 1.0f, 1.0f), color4u(0, 255, 0, 255) ) );
		}

		batch.Flush();
		batch.Clear();

		ESS()->GetGraphicsEngine()->SwapBuffers();
	}

	void OnEnter () override
	{
		TestApp::OnEnter();

		resMngr.Load( EResource::BITMAP_FONT, "font/gui_font.fnt", bfont );
		resMngr.Load( EResource::VECTOR_FONT, "font/gui_font.fnt", vfont );
		
		vfont->PreloadSymbols( 32, ' ', '~' );

		ProgramPtr	program = ESS()->GetGraphicsEngine()->GetShaderManager()->
								GetDefaultProgram( EDefaultShader::COLORED_WITH_OPACITY_MAP );

		material.SetProgram( program );
	}

	void OnExit () override
	{
		bfont = null;
		vfont = null;
		APP_BASE::OnExit();
	}
};